package com
{
	import flash.display.NativeWindow;
	import flash.display.NativeWindowInitOptions;
	import flash.display.NativeWindowResize;
	import flash.display.NativeWindowSystemChrome;
	import flash.display.NativeWindowType;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.MouseEvent;

	public class NonSquareWindow extends NativeWindow
	{
		private var _background:Sprite;
		private var _resizer:Sprite	= drawResizer();
		
		public function NonSquareWindow()
		{
			var opts:NativeWindowInitOptions = new NativeWindowInitOptions();
			opts.systemChrome 	= NativeWindowSystemChrome.NONE;
			opts.type			= NativeWindowType.LIGHTWEIGHT;
			opts.transparent	= true;
			
			super(opts);
			
			_background = new Sprite();
			_background.addEventListener(MouseEvent.MOUSE_DOWN,startMoveWindow);
			
			drawBackground(200,200);			
			stage.addChild(_background);
			stage.addChild(_resizer);
			width 	= stage.width;
			height	= stage.height;
			
			
			stage.align 	= StageAlign.TOP_LEFT;
			stage.scaleMode	= StageScaleMode.NO_SCALE;
		}
		
		private function startMoveWindow(event:MouseEvent):void{
			startMove();
		}
		
		private function drawBackground(newWidth:Number, newHeight:Number):void{
			_background.graphics.clear();
			_background.graphics.lineStyle(0,0,0);
			_background.graphics.beginFill(0x0000ff, .5);
			_background.graphics.drawRoundRectComplex(0,0,newWidth,newHeight,20,20,20,1);
			_background.graphics.beginFill(0xffffff,.9);
			_background.graphics.endFill();
		}
		
		
		private function drawResizer():Sprite{
			var s:Sprite = new Sprite();
			s.graphics.lineStyle(0,0,0);
			s.graphics.beginFill(0xcccccc,1);
			s.graphics.drawRect(0,0,10,10);
			s.graphics.endFill();
			s.x = 100;
			s.y = 180;
			
			s.addEventListener(MouseEvent.MOUSE_DOWN,startResizeWindow);
			s.addEventListener("resizing",resizingHandler);
			
			return s;
		}
		
		private function resizingHandler(event:MouseEvent):void{
			drawBackground(width,height);
			_resizer.x 	= width ;
			_resizer.y	= height;
		}
		
		private function startResizeWindow(event:MouseEvent):void{
			startResize(NativeWindowResize.BOTTOM_RIGHT);
		}
	}
}